package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.macTestConPojo;
import com.example.pojo.macTestConValPojo;
import com.example.service.macTestConService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName:macTestConController
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/12/29 16:17
 * @Version 1.0
 */
@RestController
@Slf4j
public class macTestConController {
    //注入控制层
    @Autowired
    private macTestConService macTestConService;
    //插入一行检测项目数据
    @PostMapping("macTestConInsertOne")
    public Result macTestConInsertOne(@RequestBody macTestConPojo macTestConPojo){
        //
        macTestConService.insertOne(macTestConPojo);
        return Result.success("插入成功");
    }
    //输入三个字段，进行查询
    @PostMapping("macTestConInquiryThreeField")
    public Result macTestConInquiryThreeField(@RequestBody Map<String,Object> map){
        //返回一个list
        List<macTestConPojo> macTestConPojoList = macTestConService.inquiryThreeField(map);
        return Result.success(macTestConPojoList);
    }
    //输入四个字段，进行查询
    @PostMapping("macTestConInquiryFourthField")
    public Result macTestConInquiryFourthField(@RequestBody Map<String,Object> map){
        //返回一个list
        List<macTestConPojo> macTestConPojoList = macTestConService.inquiryFourthField(map);
        return Result.success(macTestConPojoList);
    }
    //根据id，修改数据，一整行都要修改
    @PostMapping("macTestConEditOne")
    public Result macTestConEditOne(@RequestBody macTestConPojo macTestConPojo){
        macTestConService.macTestConEditOne(macTestConPojo);
        return Result.success("保存成功");
    }
    //修改一个字段.依据id
    @PostMapping("macTestConEditOneField")
    public Result macTestConEditOneField(@RequestBody Map<String,Object> map){
        macTestConService.macTestConEditOneField(map);
        return Result.success("删除成功");
    }
    //排序插入
    @PostMapping("macTestConSortInsert")
    public Result macTestConSortInsert(@RequestBody List<macTestConPojo> macTestConPojoList){
        for (int i = 0; i < macTestConPojoList.size(); i++) {
            if (macTestConPojoList.get(i).getId()==null){
                //执行插入一行的代码
                macTestConService.insertOne(macTestConPojoList.get(i));
            }
            else {
                //执行修改一个字段，修改的是顺序号
                Map<String, Object> map = new HashMap<>();
                map.put("id", macTestConPojoList.get(i).getId());
                map.put("firstFieldName", "orderNumber");
                map.put("firstFieldVal", macTestConPojoList.get(i).getOrderNumber());
                macTestConService.macTestConEditOneField(map);
            }
        }
        return Result.success("保存成功");
    }
    //接收到检测数据，对数据进行保存
    @PostMapping("/testValMacTestCon")
    public Result testValMacTestCon(@RequestBody List<macTestConValPojo> macTestConValPojos){
        //保存数据
        macTestConService.testValMacTestCon(macTestConValPojos);
        return Result.success("保存成功");
    }
    //接收5个参数，查询出检测结果。
    @PostMapping("/macTestConValInquiryFiveField")
    public Result macTestConValInquiryFiveField(@RequestBody Map<String,Object> map){
        List<macTestConValPojo> macTestConValPojos=macTestConService.macTestConValInquiryFiveField(map);
        return Result.success(macTestConValPojos);
    }
}
